const url = require('url')
const log4js = require("log4js");
log4js.configure({
  appenders: { cheese: { type: "file", filename: "cheese.log" } },
  categories: { default: { appenders: ["cheese"], level: "error" } }
});
const logger = log4js.getLogger();
logger.level = "debug";
const urlString = 'https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash'
const parsedStr = url.parse(urlString)
// logger.debug(new URL(urlString).hash);
logger.debug(parsedStr)

const myURL =
  new URL('https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash');

// const myURL = new URL('https://example.org');
// myURL.pathname = '/a/b/c';
// myURL.search = '?d=e';
// myURL.hash = '#fgh';
console.log(myURL);
logger.debug('myURL', myURL);
// console.log(myURL);
// console.log(myURL.href);
logger.debug('format', url.format(myURL, { fragment: false, unicode: true, auth: false }));

// logger.debug('format', url.format(myURL));

// const url = require('url')
// const urlObject =  {
//   protocol: 'https:',
//   slashes: true,
//   auth: null,
//   host: 'blog.csdn.net',
//   port: null,
//   hostname: 'blog.csdn.net',
//   hash: '#tag=1',
//   search: '?type=blog',
//   query: 'type=blog',
//   pathname: '/qq_41887214',
//   path: '/qq_41887214?type=blog',
//   href: 'https://blog.csdn.net/qq_41887214?type=blog#tag=1'
// }

// const parsedObj = url.format(parsedStr)
// logger.debug('parsedObj', parsedObj)
console.log(url.format(new URL('https://a:b@測試?abc#foo'), { fragment: false, unicode: true, auth: false }));


var a = url.resolve('/one/two', 'four')
var b = url.resolve('http://example.com/', '/one')
var c = url.resolve('http://example.com/one', '/two')

console.log('a', a);
console.log('b', b);
console.log('c', c);
